﻿using System;
using System.Linq;

namespace _126_按员工所属部门分组_LINQ语法
{
    class Program
    {
        static void Main(string[] args)
        {
            员工类[] 列表初始 =
            {
                new 员工类{Name="小黄",Department="财务部"},
                new 员工类{Name="小李",Department="开发部"},
                new 员工类{Name="小张",Department="行政部"},
                new 员工类{Name="小吴",Department="销售部"},
                new 员工类{Name="小刘",Department="销售部"},
                new 员工类{Name="小拳头",Department="销售部"},
                new 员工类{Name="小易",Department="行政部"},
                new 员工类{Name="小小人",Department="开发部"},
                new 员工类{Name="小米哥",Department="开发部"},
                new 员工类{Name="小大傻",Department="开发二部"}
            };

            var 查询 = from e in 列表初始
                     group e by e.Department;

            foreach (var item in 查询)
            {
                Console.WriteLine("{0}", item.Key);
                foreach (var t in item)
                {
                    Console.WriteLine(" {0}",t.Name);
                }
                Console.WriteLine();
            }

        }
    }

    public class 员工类
    {
        public string  Name { get; set; }
        public string Department { get; set; }
    }
}
